package io.gitee.zkool.barcodegun.pc;

import io.gitee.zkool.barcodegun.pc.swing.SwingClient;
import io.gitee.zkool.barcodegun.pc.ws.EmbeddedJettyWithP12;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


/**
 * @author zhaokk
 * @since 2024/2/17
 */
public class BarcodeGunPcApp {

    private static Logger log = LoggerFactory.getLogger(BarcodeGunPcApp.class);

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() ->{
            JFrame swingFrame = SwingClient.SWINGCLIENT.getFrame();
            swingFrame.setVisible(true);
            swingFrame.setResizable(false);
            swingFrame.addWindowListener(new WindowAdapter()
            {
                @Override
                public void windowClosing(WindowEvent arg0) {
                    if (JOptionPane.showConfirmDialog((JFrame) arg0.getSource(),
                            "Are you sure you want to quit?", "Exit Confirm", JOptionPane.YES_NO_OPTION,
                            JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                        log.info("exit program");
                        System.exit(0);
                    }
                }
            });
        });

        // 初始化并启动 Jetty 服务器
        try {
            EmbeddedJettyWithP12 embeddedJettyWithP12 = new EmbeddedJettyWithP12();
            embeddedJettyWithP12.server();
        } catch (Exception e) {
            log.error("Jetty 服务器启动失败", e);
        }
    }


}
